package com.xulu.romance.controller;


import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.Quarter;
import com.xulu.romance.pojo.User;
import com.xulu.romance.service.UserService;
import com.xulu.romance.utils.R;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/api/echarts")
@Api(tags = "echarts报表")
@Slf4j
public class EchartsController {

    @Autowired
    private UserService userService;


    @GetMapping("/loginNumber")
    public R loginNumber(){
        List<User> list = userService.list();
        int q1=0;
        int q2=0;
        int q3=0;
        int q4=0;
        for (User user : list) {
            Date createTime = user.getCreateTime();
            Quarter quarter = DateUtil.quarterEnum(createTime);
            switch (quarter){
                case Q1:
                    q1+=1;
                    break;
                case Q2:
                    q2+=1;
                    break;
                case Q3:
                    q3+=1;
                    break;
                case Q4:
                    q4+=1;
                    break;
                default:
                    break;
            }
        }
        return new R().put("list", CollUtil.newArrayList(q1,q2,q3,q4));
    }

}
